package com.niit.project.controller;

import com.niit.project.entity.UserGoods;
import com.niit.project.service.UserGoodsService;
import com.niit.project.service.impl.UserGoodsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.*;
import javax.servlet.http.*;
import java.io.IOException;

@WebServlet(name = "UpdateUserGoodsController", value = "/UpdateUserGoodsController")
public class UpdateUserGoodsController extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Integer id = Integer.valueOf(request.getParameter("id"));
        String username = request.getParameter("username");
        String goodname = request.getParameter("goodname");
        String goodtype = request.getParameter("goodtype");
        String changemedium = request.getParameter("changemedium");
        String changeway = request.getParameter("changeway");
        UserGoods userGoods = new UserGoods(id,username,goodname,goodtype,changemedium,changeway);
        UserGoodsService userGoodsService = new UserGoodsServiceImpl();
        userGoodsService.modifyGoods(userGoods);
        response.sendRedirect(request.getContextPath()+"/UserSelfGoodsController");
    }
}
